//
//  GYDNavigationController.swift
//  Weibo
//
//  Created by 贵永冬 on 16/7/14.
//  Copyright © 2016年 贵永冬. All rights reserved.
//

import UIKit

class GYDNavigationController: UINavigationController {
    
    
    override class func initialize() {
        let navBar = UINavigationBar.appearance()
//        navBar.backIndicatorImage = UIImage.imageWithOriginal("navigationbar_back_withtext")
//        navBar.backIndicatorTransitionMaskImage = UIImage.imageWithOriginal("navigationbar_back_withtext")
        let navItem = UIBarButtonItem.appearance()
        navItem.setBackButtonTitlePositionAdjustment(UIOffsetMake(-5, 0), forBarMetrics: .Default)
        
        
        navBar.tintColor = NAVTINTCOLOR
        let shadow = NSShadow()
        shadow.shadowOffset = CGSize.zero
        
        let normalAttributes = [NSForegroundColorAttributeName:RGB(70, g: 70, b: 70),NSFontAttributeName:UIFont.boldSystemFontOfSize(18),NSShadowAttributeName:shadow]
        navBar.titleTextAttributes = normalAttributes
        
        let barItem = UIBarButtonItem.appearance()
        barItem.setTitleTextAttributes([NSForegroundColorAttributeName:NAVTINTCOLOR,NSFontAttributeName:UIFont.systemFontOfSize(16),NSShadowAttributeName:shadow], forState: UIControlState.Normal)
        barItem.setTitleTextAttributes([NSForegroundColorAttributeName:ORGINCOLOR,NSFontAttributeName:UIFont.systemFontOfSize(16),NSShadowAttributeName:shadow], forState: UIControlState.Highlighted)
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        print(self.viewControllers.count)
        if self.viewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if self.viewControllers.count >= 1 {
                let backBar = UIBarButtonItem(title: "返回", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
                viewController.navigationItem.backBarButtonItem = backBar
            }
        }
        super.pushViewController(viewController, animated: animated)
    }
}
